package Song.Han.day05.demo02;
/*
* String中与转换相关的方法：
* */

public class Demo04StringConvert {
    public static void main(String[] args) {

        //转换为字符数组
        char[] chars = "Hello".toCharArray();
        System.out.println(chars[0]);
        System.out.println(chars.length);
        System.out.println("---------------------");

        //转换为字节数组
        byte[] bytes = "abc".getBytes();
        System.out.println(bytes[0]);
        System.out.println(bytes[1]);
        System.out.println(bytes[2]);
        System.out.println("---------------------");

        //将老字符串替换成为新字符串，返回替代之后的新字符串
        String str1 = "How do you do？";
        String str2 = str1.replace("o","*");
        System.out.println(str1);
        System.out.println(str2);
        System.out.println("---------------------");

        //例子：敏感词过滤
        String lang1 = "臭傻逼，玩尼玛呢！";
        String lang2 = lang1.replace("傻逼","**");
        String lang3 = lang2.replace("尼玛","**");
        System.out.println(lang1);
        System.out.println(lang3);
    }
}
